const api = require('../../utils/api.js');
const app = getApp();

Page({
  data: {
    order_refund: null,
    unit: '',
    again: true,
    hide: 1,
    qrcode: '',
  },
  onLoad(options) {
    let that = this;
    let entry = options.entry || '';
    app.pageOnLoad(this);
    app.loadCurrencyUnit().then(res => {
      that.setData({
        unit: res.unit,
      });
    });
    wx.showLoading({
      title: '正在加载',
    });
    if (entry) {
      let url = '';
      if (entry === 'default') {
        url = api.order.refund_detail;
      } else if (entry === 'ms') {
        url = api.miaosha.refund_detail;
      } else if (entry === 'pt') {
        url = api.group.order.refund_detail;
      }
      app.ws_micro_shoprequest({
        url,
        data: {
          order_refund_id: options.id,
        },
        success: function(res) {
          if (res.code === 0) {
            that.setData({
              order_refund: res.data,
            });
          }
        },
        complete: function() {
          wx.hideLoading();
        },
      });
    } else {
      app.util.navigateTo('/ws_micro_shop/pages/user/user');
    }
    app.loadShopSetting().then(res => {
      that.setData(res);
    });
  },

  customerTo() {
    let { card_openid, card_toopenid, card_id } = this.data;
    let url = '/common/component/universal-card/pages/message?openid=' + card_openid + '&to_openid=' + card_toopenid + '&cardid=' + card_id + '&scene=inner&m_id=0';
    app.util.navigateTo(url);
  },

  viewImage(e) {
    let index = e.currentTarget.dataset.index;
    wx.previewImage({
      current: this.data.order_refund.refund_pic_list[index],
      urls: this.data.order_refund.refund_pic_list,
    });
  },
});
